<?php
if ( !defined('KAIZEKU') ) {die( 42);}
/**
 * WP-iStalker Chrome Min 
 * Formatting
 * 
 * PHP 4 & 5
 * 
 * @package		WordPress
 * @subpackage	wp-istalker-chrome-min
 * 
 * @category	TemplateHelper
 * @author		Avice (ChaosKaizer) De'vereux <ck+wp-istalker-min@istalker.net>
 * @author		NH. Noah <noah+wp-istalker-min@kakkoi.net>
 * @copyright 	2007 - 2009 Avice De'vereux, NH. Noah
 * @license 	http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License v2 
 * @version 	CVS: $Id: formatting.php 8 2009-01-09 04:37:51Z chaoskaizer $
 * @since 		0.1
 */


/**
 * HTML tag Helper function 
 * function _t()
 * 
 * @author Avice (chaoskaizer ) Devereux <ck+filtered@animepaper.net> 
 * @param string		$tag html tagname; a p strong
 * @param mixed|string	$content			the content 
 * @param mixed|array	$htmlattributes 	html tag attributes in pair key value
 * @uses  attribute_escape() Escaping for HTML attributes
 * @since 0.1
 * 
 * example
 * <code>
 * echo _t('a','website',array('href'=>'http://blog.kaizeku.com'));
 * echo _t('script','',array('src'=>'http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'));
 * </code>
 */
function _t($tag = 'a', $content = false, $htmlattributes = false){

	$htm = '<' . $tag;

		if (is_array($htmlattributes)){
	
			// add name || id for input
			if ($tag == 'input'){
				
				if (isset($htmlattributes['id'])){
					
					$htmlattributes['name'] = $htmlattributes['id'];					
				} elseif (isset($htmlattributes['name'])){
					
					$htmlattributes['id'] = $htmlattributes['name'];
				}	
			}
	
			$esc_prop = array_flip(array('title', 'alt', 'caption', 'content'));
	
			foreach ($htmlattributes as $name => $txt){
	
				$name = strtolower($name);
	
				if ($tag == 'blockquote'){
					if ($name == 'cite'){
						$txt = urlencode($txt);
					}
				}
	
				if (isset($esc_prop[$name])){
					
					$htm .= ' ' . $name . '="' . attribute_escape($txt) . '"';					
				} else {
					
					$htm .= ' ' . $name . '="' . $txt . '"';
				}
			}
	
	
			unset($htmlattributes, $esc_prop, $name, $txt);
		}

	$typesingle = array_flip(array('img', 'input', 'hr', 'link', 'meta', 'br'));
	
	$htm .= (isset($typesingle[$tag])) ? ' />' : '>' . $content . '</' . $tag . '>';
	
	$newline_tag = array_flip(array('h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'ul',
		'ol', 'dl', 'li', 'script', 'pre', 'code', 'div', 'form', 'table', 'dt', 'dd',
		'blockquote', 'meta', 'link', 'title'));

		if (isset($newline_tag[$tag])){
			$htm .= PHP_EOL;
		}

	unset($typesingle, $newline_tag, $tag, $content);

	return $htm;
}


/**
 * @see _t
 */
function t($tag = 'a', $content = false, $htmlattributes = false){
	echo _t($tag, $content, $htmlattributes);
}	
?>